#!/usr/bin/env python
#usage: monitor_form.py monitor_sphere.txt
import sys
import numpy as np
import os

f = open(sys.argv[1],'r')
lines = f.readlines()
f.close()
#f1 = open(sys.argv[2],'a')
f1 = open('tmp.txt','a')
for i in range(len(lines)):
    if i%2 == 0:
        timetag = lines[i].split('\t')[0]
        print(timetag)
        currents = lines[i].split('\t')[1]
        currents = currents.split(',')
        c = np.zeros(len(currents))
        for j in range(len(currents)):
            c[j] = float(currents[j])
        wline = timetag+' '+str(np.median(c))+'\n'
        f1.writelines(wline)
f1.close()
os.system("mv tmp.txt " + sys.argv[1])
